import request from "@/utils/request";

class MenuAPI {
  /**
   * 获取当前用户的路由列表
   * <p/>
   * 无需传入角色，后端解析token获取角色自行判断是否拥有路由的权限
   *
   * @returns 路由列表
   */
  static getRoutes() {
    return request<any, RouteVO[]>({
      url: "/api/v1/menus/routes",
      method: "get",
    });
  }

  static getLocalRoutes() {
    // return request<any, RouteVO[]>({
    //   url: "/api/v1/menus/routes",
    //   method: "get",
    // });
    return new Promise((resolve) => {
      setTimeout(() => {
        const mockMenuData = [
          {
            path: "/system",
            component: "Layout",
            redirect: "/system/user",
            name: "/system",
            meta: {
              title: "系统管理",
              icon: "system",
              hidden: false,
              alwaysShow: false,
              params: null,
            },
            children: [
              {
                path: "user",
                component: "system/user/index",
                name: "User",
                meta: {
                  title: "用户管理",
                  icon: "el-icon-User",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "role",
                component: "system/role/index",
                name: "Role",
                meta: {
                  title: "角色管理",
                  icon: "role",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "menu",
                component: "system/menu/index",
                name: "Menu",
                meta: {
                  title: "菜单管理",
                  icon: "menu",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "dept",
                component: "system/dept/index",
                name: "Dept",
                meta: {
                  title: "部门管理",
                  icon: "tree",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "dict",
                component: "system/dict/index",
                name: "Dict",
                meta: {
                  title: "字典管理",
                  icon: "dict",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "log",
                component: "system/log/index",
                name: "Log",
                meta: {
                  title: "系统日志",
                  icon: "document",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "config",
                component: "system/config/index",
                name: "Config",
                meta: {
                  title: "系统配置",
                  icon: "setting",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
            ],
          },
          {
            path: "/doc",
            component: "Layout",
            redirect: "https://juejin.cn/post/7228990409909108793",
            name: "/doc",
            meta: {
              title: "平台文档",
              icon: "document",
              hidden: false,
              alwaysShow: false,
              params: null,
            },
            children: [
              {
                path: "internal-doc",
                component: "demo/internal-doc",
                name: "InternalDoc",
                meta: {
                  title: "菜单内嵌iframe",
                  icon: "document",
                  hidden: false,
                  alwaysShow: false,
                  params: null,
                },
              },
              // {
              //   path: "https://juejin.cn/post/7228990409909108793",
              //   name: "Https://juejin.cn/post/7228990409909108793",
              //   meta: {
              //     title: "平台文档(外链)",
              //     icon: "el-icon-Link",
              //     hidden: false,
              //     alwaysShow: false,
              //     params: null,
              //   },
              // },
            ],
          },
          {
            path: "/multi-level",
            component: "Layout",
            name: "/multiLevel",
            meta: {
              title: "多级菜单",
              icon: "cascader",
              hidden: false,
              alwaysShow: true,
              params: null,
            },
            children: [
              {
                path: "multi-level1",
                component: "demo/multi-level/level1",
                name: "MultiLevel1",
                meta: {
                  title: "菜单一级",
                  icon: "",
                  hidden: false,
                  alwaysShow: true,
                  params: null,
                },
                children: [
                  {
                    path: "multi-level2",
                    component: "demo/multi-level/children/level2",
                    name: "MultiLevel2",
                    meta: {
                      title: "菜单二级",
                      icon: "",
                      hidden: false,
                      alwaysShow: false,
                      params: null,
                    },
                    children: [
                      {
                        path: "multi-level3-1",
                        component:
                          "demo/multi-level/children/children/level3-1",
                        name: "MultiLevel31",
                        meta: {
                          title: "菜单三级-1",
                          icon: "",
                          hidden: false,
                          keepAlive: true,
                          alwaysShow: false,
                          params: null,
                        },
                      },
                      {
                        path: "multi-level3-2",
                        component:
                          "demo/multi-level/children/children/level3-2",
                        name: "MultiLevel32",
                        meta: {
                          title: "菜单三级-2",
                          icon: "",
                          hidden: false,
                          keepAlive: true,
                          alwaysShow: false,
                          params: null,
                        },
                      },
                    ],
                  },
                ],
              },
            ],
          },
          {
            path: "/component",
            component: "Layout",
            name: "/component",
            meta: {
              title: "组件封装",
              icon: "menu",
              hidden: false,
              alwaysShow: false,
              params: null,
            },
            children: [
              {
                path: "curd",
                component: "crud/index",
                name: "Curd",
                meta: {
                  title: "增删改查",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "card-list",
                component: "demo/card-list/index",
                name: "CardList",
                meta: {
                  title: "卡片列表",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "multiple-forms",
                component: "demo/form/multiple-forms/index",
                name: "MultipleForms",
                meta: {
                  title: "多表单验证",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "dynamic-form",
                component: "demo/form/dynamic-form/index",
                name: "DynamicForm",
                meta: {
                  title: "动态复杂表单",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "wang-editor",
                component: "demo/wang-editor",
                name: "WangEditor",
                meta: {
                  title: "富文本编辑器",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "upload",
                component: "demo/upload",
                name: "Upload",
                meta: {
                  title: "文件上传",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "icon-selector",
                component: "demo/icon-selector",
                name: "IconSelector",
                meta: {
                  title: "图标选择器",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "dict-demo",
                component: "demo/dict",
                name: "DictDemo",
                meta: {
                  title: "字典组件",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "echarts",
                component: "demo/echarts/index",
                name: "echarts",
                meta: {
                  title: "Echarts图表",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
              {
                path: "form-design",
                component: "demo/form/form-design/index",
                name: "FormDesign",
                meta: {
                  title: "表单设计器",
                  icon: "",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
            ],
          },
          {
            path: "/function",
            component: "Layout",
            name: "/function",
            meta: {
              title: "功能演示",
              icon: "menu",
              hidden: false,
              alwaysShow: false,
              params: null,
            },
            children: [
              {
                path: "map",
                component: "demo/map/index",
                name: "GisMap",
                meta: {
                  title: "GIS地图",
                  icon: "el-icon-Notification",
                  hidden: false,
                  keepAlive: true,
                  alwaysShow: false,
                  params: null,
                },
              },
            ],
          },
        ];
        resolve(mockMenuData);
      }, 300);
    });
  }
}

export default MenuAPI;

/** RouteVO，路由对象 */
export interface RouteVO {
  /** 子路由列表 */
  children: RouteVO[];
  /** 组件路径 */
  component?: string;
  /** 路由属性 */
  meta?: Meta;
  /** 路由名称 */
  name?: string;
  /** 路由路径 */
  path?: string;
  /** 跳转链接 */
  redirect?: string;
}

/** Meta，路由属性 */
export interface Meta {
  /** 【目录】只有一个子路由是否始终显示 */
  alwaysShow?: boolean;
  /** 是否隐藏(true-是 false-否) */
  hidden?: boolean;
  /** ICON */
  icon?: string;
  /** 【菜单】是否开启页面缓存 */
  keepAlive?: boolean;
  /** 路由title */
  title?: string;
}
